package com.example.demo.controller.system;

import com.example.demo.annoation.Log;
import com.example.demo.bean.AjaxRes;
import com.example.demo.bean.sysfile.SysFileDO;
import com.example.demo.controller.BaseAdminController;
import com.example.demo.enums.BusinessType;
import com.example.demo.service.ISysFileService;
import com.example.demo.dto.sysfile.SysFilePageReqVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping(value = "/system/sys_file")
@RestController
public class SysFileController extends BaseAdminController {

    @Resource
    private ISysFileService sysFileService;

    @GetMapping("/list")
    public AjaxRes list(SysFilePageReqVO sysFilePageReqVO) {
        return AjaxRes.success(sysFileService.list(sysFilePageReqVO));
    }

    @PutMapping("/rename")
    @Log(title = "文件重命名", businessType = BusinessType.UPDATE)
    public AjaxRes rename(@RequestBody SysFileDO sysFileDO) {
        return toAjax(sysFileService.renameSysFile(sysFileDO));
    }

    @PutMapping("/move/{fileId}")
    @Log(title = "文件移动", businessType = BusinessType.UPDATE)
    public AjaxRes move(@PathVariable("fileId") Long[] fileId,@RequestBody SysFileDO sysFileDO) {
        return toAjax(sysFileService.moveSysFile(fileId,sysFileDO));
    }

    @DeleteMapping("/delete/{fileIds}")
    @Log(title = "文件删除", businessType = BusinessType.DELETE)
    public AjaxRes delete(@PathVariable("fileIds") Long[] fileIds) {
        return toAjax(sysFileService.deleteSysFile(fileIds));
    }

    @GetMapping("/{fileId}")
    public AjaxRes query(@PathVariable("fileId") Long fileId) {
        return AjaxRes.success(sysFileService.getSysFile(new SysFileDO().setId(fileId)));
    }
}
